﻿@model CP_SchoolForChildren_v0._1.Models.RelatedModel.ArticleModel
@using CP_SchoolForChildren_v0._1.Models.DataModel
@{
    ViewBag.Title = Model.Title;
    Layout = "~/Views/Shared/FE/_Layout_FE_Index.cshtml";
    SFCEntities db = new SFCEntities();
}
<style type="text/css">
    .article-tile h2 {
        color: #774F38;
        padding: 5px;
        margin: 5px;
    }
    .article-content {
        padding: 15px;
        margin-top: 25px;
        line-height: 20px;
    }
    .relatedpost {
        margin-bottom: 10px;
        padding-left: 15px;
        line-height: 20px;
        font-size: 14px;
        
    }
    .relatedpost a {
        text-decoration: none;
        color: #000;
    }
    .relatedpost a:hover 
    {
        text-decoration: underline;
        color: #774F38;
    }
</style>
<link href="@Url.Content("~/Content/FE/Addition.css")" rel="stylesheet" type="text/css" />
<div class="allhome" style="padding-top: 15px;">
<div class="dashboard" style="width: 305px;">
    <div class="content-header">
        <div class="header-inner">
            <h2><a href="@Url.Action("Index")">Chuyên mục</a></h2>
            <br class="spacer"/>
            <ol class="rectangle-list">
                @{
                    List<Category> category = (from c in db.Categories
                                               select c).ToList<Category>();

                    for (int i = 1; i <= category.Count; i++)
                    {
                        <li> @Html.ActionLink(category[i - 1].CategoryName, "ViewArticleByCategory", new {id = category[i - 1].CategoryID})</li>
                    }

                }
            </ol>
        </div>
    </div>
</div>
    <div class="content-main" style="width: 650px;">
        <div class="boxMod" >
            <div class="article-tile">
                <h2>@Model.Title</h2>
                <small class="time"><p style="font-style: italic; color: #2f3a52">Gửi lúc: @Model.CreatedTime</p></small>
            </div>
            
            <div class="article-content">
                @(new HtmlString(Model.ArticleContent))
        
                <br class="spacer"/>
                @if (User.Identity.Name != "")
                {
                    string name = User.Identity.Name;
                    var user = (from u in db.Users
                                where (u.UserName == name)
                                select u).First();
                    var article = (from a in db.Articles
                                   where a.ArticleID == Model.ArticleID
                                   select a).First();
                    var roleadmin = db.UserRoles.Single(ur => ur.RoleName == "Admin");
                    int userid = user.UserID;
                    if (userid == Model.UserID ||
                        user.RoleID == roleadmin.RoleID)
                    {
                        <p id="article-cp"> @Html.ActionLink("Chỉnh sửa", "Edit", new { id = Model.ArticleID }) 
                            | @Html.ActionLink("Xóa", "Delete", new { id = Model.ArticleID })</p>
                                
                    }
                }
            </div>   
           
        </div>
        <div class="boxRelated">
            <h2 style="color: #774F38; margin-bottom: 10px; cursor: default;">Các bài viết khác</h2>
            @{
                List<Article> art = (from a in db.Articles
                                     where a.CategoryID == Model.CategoryID
                                     select a).OrderByDescending(a => a.CreatedTime).ToList();
                for (int i = art.Count - 3; i <= art.Count; i++)
                {
                    if (i >=1)
                    {
                        
                        <div class="relatedpost">@Html.ActionLink(art[i - 1].Title, "Details", new { id = art[i - 1].ArticleID })</div>
                        
                    }
                }
            }
        </div>
        <br class="spacer"/>
        </div>
    <br class="spacer"/>
</div>